from rest_framework import viewsets
from rest_framework.response import Response
from .models import Warehouse, Project
from .serializers import WarehouseSerializer, ProjectSerializer

# ------------ 仓库管理接口 ------------
class WarehouseViewSet(viewsets.ModelViewSet):
    """
    仓库的增删改查接口
    - 使用 ModelViewSet 自动生成 CRUD 接口
    - queryset: 指定数据查询集
    - serializer_class: 指定序列化器
    """
    queryset = Warehouse.objects.filter(status='active')  # 仅显示在用仓库
    serializer_class = WarehouseSerializer

# ------------ 项目管理接口 ------------
class ProjectViewSet(viewsets.ModelViewSet):
    """
    项目的增删改查接口
    - 项目编码（project_id）为主键，格式为 "001-001-001"
    """
    queryset = Project.objects.all()
    serializer_class = ProjectSerializer

    def perform_create(self, serializer):
        # 可在此处添加自定义校验逻辑（如编码结构）
        super().perform_create(serializer)